<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" :inline="true" size="small" label-width="90px" v-show="showSearch">
      <el-form-item label="库存ID" prop="inventoryId">
        <el-input v-model="queryParams.inventoryId" placeholder="请输入库存ID" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="SKU ID" prop="skuId">
        <el-input v-model="queryParams.skuId" placeholder="请输入SKU ID" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="业务单号" prop="bizNo">
        <el-input v-model="queryParams.bizNo" placeholder="请输入业务单号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   v-hasPermi="['wms:inventorylog:export']">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"/>
    </el-row>

    <el-table v-loading="loading" :data="logList">
      <el-table-column label="库存ID" prop="inventoryId" width="120"/>
      <el-table-column label="仓库ID" prop="warehouseId" width="120"/>
      <el-table-column label="货位ID" prop="locationId" width="120"/>
      <el-table-column label="SKU ID" prop="skuId" width="120"/>
      <el-table-column label="批次号" prop="batchNo" min-width="140"/>
      <el-table-column label="业务类型" prop="bizType" width="120"/>
      <el-table-column label="业务单号" prop="bizNo" min-width="150"/>
      <el-table-column label="变动类型" prop="changeType" width="120"/>
      <el-table-column label="变动数量" prop="changeQuantity" width="120"/>
      <el-table-column label="变后数量" prop="afterQuantity" width="120"/>
      <el-table-column label="操作人" prop="createName" width="120"/>
      <el-table-column label="操作时间" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
  </div>
</template>

<script>
import {getInventoryLog, listInventoryLog} from '@/api/wms/inventoryLog'

export default {
  name: 'WmsInventoryLog',
  data() {
    return {
      loading: false,
      showSearch: true,
      total: 0,
      logList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        inventoryId: undefined,
        skuId: undefined,
        bizNo: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      listInventoryLog(this.queryParams).then(res => {
        this.logList = res.rows || []
        this.total = res.total || 0
        this.loading = false
      })
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleExport() {
      this.download('/wms/inventory-log/export', {...this.queryParams}, `inventory_log_${new Date().getTime()}.xlsx`)
    },
    viewDetail(row) {
      getInventoryLog(row.id).then(res => {
        this.$modal.alert(JSON.stringify(res.data, null, 2), '库存流水详情')
      })
    }
  }
}
</script>

